package org.wanda.pv.framework.base;

import com.fasterxml.jackson.annotation.JsonFormat;
import org.nutz.dao.entity.annotation.*;
import org.nutz.json.Json;
import org.nutz.lang.Times;
import org.nutz.lang.random.R;
import org.wanda.pv.framework.ig.GenId;

import java.io.Serializable;
import java.util.Date;

public abstract class BaseModel implements Serializable {
    private static final long serialVersionUID = 1L;
    @Column

    @Comment("操作人")
    //@Prev(els = @EL("$me.uid()"))
    @ColDefine(type = ColType.VARCHAR, width = 32)
    private String opBy;

    @Column
    @Comment("创建时间")
    @Prev(els = @EL("$me.date()"))
    @ColDefine(type = ColType.DATETIME)
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm")
    private Date createDT;


    @Column
    @Comment("修改时间")
    @ColDefine(type = ColType.DATETIME)
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm")
    private Date updateDT;


    @Column
    @Comment("操作时间")
    @Prev(els = @EL("$me.now()"))
    @ColDefine(type = ColType.INT,width = 9)
    private Long opAt;

    @Column
    @Comment("删除标记")
    @Prev(els = @EL("$me.flag()"))
    @ColDefine(type = ColType.BOOLEAN)
    private Boolean delFlag;

    public String toString() {
        return String.format("/*%s*/%s", super.toString(), Json.toJson(this, org.nutz.json.JsonFormat.compact()));
    }

    public Boolean flag() {
        return false;
    }

    public Long now() {
        return Times.getTS();
    }
    public Date date() {
        return new Date();
    }


    public String getOpBy() {
        return opBy;
    }

    public void setOpBy(String opBy) {
        this.opBy = opBy;
    }

    public Long getOpAt() {
        return opAt;
    }

    public void setOpAt(Long opAt) {
        this.opAt = opAt;
    }

    public Boolean getDelFlag() {
        return delFlag;
    }

    public void setDelFlag(Boolean delFlag) {
        this.delFlag = delFlag;
    }

    public String uuid() {
        return R.UU32().toLowerCase();
    }

    public Date getCreateDT() {
        return createDT;
    }

    public void setCreateDT(Date createDT) {
        this.createDT = createDT;
    }

    public Date getUpdateDT() {
        return updateDT;
    }

    public void setUpdateDT(Date updateDT) {
        this.updateDT = updateDT;
    }

    public Long idGen(){
        return  GenId.getInstance().nextId();
    }
}
